﻿
using UnityEngine;
using UnityEngine.UI;
public class CYTLVTWO_SideSwitcher : MonoBehaviour
{


    private void Start()
    {
        //设置屏幕常亮
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        btnOpenAnnouncement.onClick.AddListener(OnCLickOpenWebViewInRectTrans);
        btnCloseAnnouncement.onClick.AddListener(OnCLickCloseWebviewPanel);
    }

    #region 公告
    [Header("公告URL")]
    public string announceURL;
    [Header("公告面板")]
    public GameObject AnnouncementFrame;
    [Header("公告显示区域")]
    public RectTransform AnnouncementShowRectTrans;
    [Header("打开公告的按钮")]
    public Button btnOpenAnnouncement;
    [Header("关闭公告的按钮")]
    public Button btnCloseAnnouncement;
    UniWebView newView;

    private GameObject webViewContainer;
    public void OnCLickOpenWebViewInRectTrans()
    {
        //CYTLVTWO_NetworkBase.Instance.PostPageName("开始页-点击公告");
        AnnouncementFrame.SetActive(true);
        if (Application.internetReachability != NetworkReachability.NotReachable)
        {
            webViewContainer = new GameObject();
            newView = webViewContainer.AddComponent<UniWebView>();
            newView.ReferenceRectTransform = AnnouncementShowRectTrans;
            newView.SetShowSpinnerWhileLoading(true);
            newView.SetZoomEnabled(true);
            newView.Load(this.announceURL);
            newView.Show();
        }
    }
    public void OnCLickCloseWebviewPanel()
    {
        if (newView != null)
        {
            newView.Hide();
        }
        if (webViewContainer != null)
        {
            Destroy(webViewContainer);
            webViewContainer = null;
        }
        AnnouncementFrame.SetActive(false);
    }
    #endregion

}

